package iec104;

public class DIQ {
	private byte spi = 0;
	private byte res = 0;
	private byte bl = 0;
	private byte sb = 0;
	private byte nt = 0;
	private short iv = 0;
	private short diq;

	short setDIQ(int spi0, boolean bl0, boolean sb0, boolean nt0, boolean iv0) {
		this.spi = (byte) (spi0 & 0x03);
		if (bl0)
			this.bl = (byte) (1 << 4);
		if (sb0)
			this.sb = (byte) (1 << 5);
		if (nt0)
			this.nt = (byte) (1 << 6);
		if (iv0)
			this.iv = (short) (1 << 7);
		diq = (short) (spi + res + bl + sb + nt + iv);
		return diq;
	}
	void setDIQ(short diq)
	{
		spi=(byte) (diq&0x03);
		bl=(byte) ((diq>>4)&0x01);
		sb=(byte) ((diq>>5)&0x01);
		nt=(byte) ((diq>>6)&0x01);
		iv=(byte) ((diq>>7)&0x01);		
	}
	String tostring() {
		String diqstr = new String();
		diqstr = diqstr.concat(" spi:" + Integer.toString(spi));
		diqstr = diqstr.concat(" res:" + Integer.toString(0));
		diqstr = diqstr.concat(" bl:" + Integer.toString(bl >> 4));
		diqstr = diqstr.concat(" sb:" + Integer.toString(sb >> 7));
		diqstr = diqstr.concat(" nt:" + Integer.toString(nt >> 6));
		diqstr = diqstr.concat(" iv:" + Integer.toString(iv >> 7));
		return diqstr;
	}

}
